//
//  OpenGreenLaisee.m
//  Staff
//
//  Created by caiyao on 1/15/15.
//
//

#import "OpenGreenLaisee.h"
#import "HookWebViewController.h"
#import "OnboardingViewController.h"
#import "AppDelegate.h"
#import "NSData-AES.h"
#import "GreenController.h"
#import "JSONKit.h"
#import "commonDefines.h"
@implementation OpenGreenLaisee

- (void)openGreenLaisee:(CDVInvokedUrlCommand*)command {
    NSLog(@"command===%@",command);
    if ([command.arguments count]>0) {
        NSString *accountInfo = [[command arguments] objectAtIndex:0];
        
        NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
        NSData *data=[[accountInfo dataUsingEncoding:NSUTF8StringEncoding]
                      AES256EncryptWithKey:secureToken];
        [defs setObject:data forKey:@"customerInfo"];
        [defs synchronize];
       
        NSData *data1 = [defs objectForKey:@"customerInfo"];
        NSData *encryptedData = [NSData dataWithData:data1];
        NSData *saveData = [encryptedData AES256DecryptWithKey:secureToken];
        NSString *userInfo = [[NSString alloc] initWithData:saveData encoding:NSUTF8StringEncoding];
        
 		NSDictionary *dic = [userInfo objectFromJSONString];
        NSLog(@"dic===%@",dic);
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:[dic objectForKey:@"account"] forKey:GREEN_USER_ID];
        [defaults synchronize];
    }
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"OnboardingHasShow"]) {
        OnboardingViewController *controller = [[OnboardingViewController alloc] init];
        [[(AppDelegate *)[[UIApplication sharedApplication] delegate] viewController].navigationController pushViewController:controller animated:YES];
    } else {
        HookWebViewController *controller = [[HookWebViewController alloc] init];
        [[(AppDelegate *)[[UIApplication sharedApplication] delegate] viewController].navigationController pushViewController:controller animated:YES];
    }
    
}

@end
